In [1]:
from vector2d_v0 import Vector2d
In [2]:
v1 = Vector2d(3, 4)
print(v1.x, v1.y)
In [3]:
x, y = v1
In [4]:
x, y
Out[4]:
In [5]:
v1
Out[5]:
In [6]:
v1_clone = eval(repr(v1))
v1 == v1_clone
Out[6]:
In [7]:
print(v1)
In [8]:
octets = bytes(v1)
In [9]:
octets
Out[9]:
In [10]:
abs(v1)
Out[10]:
In [11]:
bool(v1), bool(Vector2d(0, 0))
Out[11]:
In [1]:
class Demo:
@classmethod
def klassmeth(*args):
return args
@staticmethod
def statmeth(*args):
return args
In [2]:
Demo.klassmeth()
Out[2]:
In [5]:
Demo.klassmeth('spam')
Out[5]:
In [3]:
Demo.statmeth()
Out[3]:
In [4]:
Demo.statmeth('spam')
Out[4]:
In [6]:
brl = 1/2.43
In [7]:
brl
Out[7]:
In [8]:
format(brl, '0.4f')
Out[8]:
In [23]:
'1 BRL = {rate:0.2f} USD'.format(rate=brl)
Out[23]:
In [24]:
format(42, 'b')
Out[24]:
In [25]:
format(2/3, '.1%')
Out[25]:
In [ ]:
from datetime import datetime
In [28]:
now = datetime.now()
format(now, '%H:%M:%S')
Out[28]:
In [29]:
"It's now {:%I:%M %p}".format(now)
Out[29]:
In [13]:
import vector2d_v1
In [14]:
from vector2d_v1 import Vector2d
In [2]:
v1 = Vector2d(3, 4)
format(v1)
Out[2]:
In [3]:
format(v1, '.3f')
Out[3]:
In [15]:
format(Vector2d(1, 1), 'p')
Out[15]:
In [5]:
format(Vector2d(1, 1), '.3ep')
Out[5]:
In [6]:
format(Vector2d(1, 1), '0.5fp')
Out[6]:
In [7]:
format(Vector2d(1, 1), '0.5f')
Out[7]:
In [1]:
from vector2d_v1 import Vector2d
In [2]:
v1 = Vector2d(3, 4)
In [3]:
hash(v1)
In [4]:
v1.x, v1.y
Out[4]:
In [5]:
v1.x = 7
In [6]:
v1.x, v1.y
Out[6]:
In [8]:
import vector2d_v3 as v2d3
In [10]:
v1 = v2d3.Vector2d(3, 4)
v2 = v2d3.Vector2d(3.1, 4.2)
hash(v1), hash(v2)
Out[10]:
In [11]:
set([v1, v2])
Out[11]:
In [12]:
v1_clone = v2d3.Vector2d.frombytes(bytes(v1))
In [13]:
v1_clone
Out[13]:
In [14]:
v1 == v1_clone
Out[14]:
In [15]:
v1 = v2d3.Vector2d(3, 4)
v1.__dict__
Out[15]:
In [16]:
v1._Vector2d__x
Out[16]:
In [17]:
import vector2d_v3 as v2d3
In [18]:
v1 = v2d3.Vector2d(1.1, 2.2)
dumpd = bytes(v1)
dumpd
Out[18]:
In [19]:
len(dumpd)
Out[19]:
In [20]:
v1.typecode = 'f'
dumpf = bytes(v1)
dumpf
Out[20]:
In [21]:
len(dumpf)
Out[21]:
In [22]:
v2d3.Vector2d.typecode
Out[22]:
In [23]:
class ShortVector2d(v2d3.Vector2d):
typecode = 'f'
In [24]:
sv = ShortVector2d(1/11, 1/27)
sv
Out[24]:
In [25]:
len(bytes(sv))
Out[25]:
In [28]:
type(sv)
Out[28]:
In [30]:
class Foo(object):
def bar(self, arg1, arg2):
print(arg1, arg2)
In [31]:
foo = Foo()
In [32]:
foo.bar(1,2)
In [38]:
Foo.__dict__['bar'].__get__(foo, type(foo))(1,2)
In [40]:
def foo(cls):
print(cls)
In [41]:
classmethod(foo)
Out[41]:
In [42]:
cm = classmethod(foo)
In [43]:
cm.__get__(None, dict)
Out[43]:
In [44]:
cm.__get__(None, dict)()
In [45]:
cm.__get__({}, dict())
Out[45]:
In [46]:
cm.__get__({}, dict())()
In [47]:
cm.__get__("Some bogus unused string", dict())()
In [ ]: